package edu.fsu.cs.SHPE;

import java.net.ConnectException;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class SessionListAdapter extends BaseAdapter {

	private SessionContainer sessionContainer;
	private LayoutInflater inFlate;
	
	public SessionListAdapter(Context context, String url) throws ConnectException{
		sessionContainer = new SessionContainer(url);
		inFlate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		context = null;
 	}
	
	public void setViewableSessionsByTrackId(long id){
		sessionContainer.setViewableSessionsByTrackId(id);
	}
	
	
	@Override
	public int getCount() {
		return sessionContainer.getViewableList().size();
	}

	@Override
	public Object getItem(int position) {
		return sessionContainer.getViewableList().get(position);
	}

	@Override
	public long getItemId(int position) {
		return sessionContainer.getViewableList().get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if(convertView == null)
			convertView = inFlate.inflate(R.layout.sessionitem, null);
		
		TextView tmp;
		Session tmpSession = sessionContainer.getViewableList().get(position);
		
		if(tmpSession.getTitle() != null){
			tmp = (TextView)convertView.findViewById(R.id.txtTitle);
			tmp.setText(tmpSession.getTitle());
		}
		
		if(tmpSession.getStartTime() != null){
			tmp = (TextView) convertView.findViewById(R.id.txtStartTime);
			tmp.setText(tmpSession.getStartTime() + "- ");
		}
		
		if(tmpSession.getEndTime() != null){
			tmp = (TextView) convertView.findViewById(R.id.txtEndTime);
			tmp.setText(tmpSession.getEndTime());
		}
		
		if(tmpSession.getRoom() != null){
			tmp = (TextView) convertView.findViewById(R.id.txtRoom);
			tmp.setText(tmpSession.getRoom());
		}
		

		return convertView;
	}

}
